package com.autoglm.android.core.models

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName

/**
 * 应用信息，包含应用的界面和操作知识
 */
data class AppInfo(
    val appName: String,
    val packageName: String,
    val commonScreens: List<ScreenInfo> = emptyList(),
    val commonElements: List<UIElement> = emptyList(),
    val operationKnowledge: List<AppOperation> = emptyList()
) {
    /**
     * 转换为JSON字符串
     */
    fun toJson(): String {
        return Gson().toJson(this)
    }
    
    companion object {
        /**
         * 从JSON字符串解析
         */
        fun fromJson(json: String): AppInfo {
            return Gson().fromJson(json, AppInfo::class.java)
        }
    }
}

/**
 * 屏幕信息
 */
data class ScreenInfo(
    val screenName: String,
    val description: String,
    val activityName: String,
    val elements: List<UIElement> = emptyList()
)

/**
 * UI元素
 */
data class UIElement(
    val elementId: String,
    val description: String,
    val screenName: String,
    val resourceId: String? = null,
    val className: String? = null,
    val text: String? = null,
    val contentDescription: String? = null,
    val bounds: String? = null
)

/**
 * 应用操作知识
 */
data class AppOperation(
    val operation: String,
    val description: String,
    val steps: String
)

/**
 * 矩形区域数据类，表示UI元素在屏幕上的位置
 */
data class Rect(
    val left: Int,
    val top: Int,
    val right: Int,
    val bottom: Int
) {
    val width: Int get() = right - left
    val height: Int get() = bottom - top
    val centerX: Int get() = left + width / 2
    val centerY: Int get() = top + height / 2
} 